#include "stdio.h"
#include "iostream"
using namespace std;
class Stack_Queue
{
public:
    typedef struct{
        int data[10];
        int top;
    }SqStack;
    SqStack Sqstack;
    typedef struct 
    {
        int data[10];
        //front指向数据头，rear指向下一个要存储的地址
        int front, rear;
    }SqQueue;
    SqQueue sqQueue;
public:
    bool push(SqStack &s, int x){
        if(s.top == 9)
            return false;
        s.data[++s.top] = x;
        cout << x << " ";
        return true;
    }
    bool pull(SqStack &s, int &x){
        if(s.top == -1)
            return false;
        x = s.data[s.top--];
        return true;
    }
    void testStack(){
        Sqstack.top = -1;
        int x;
        cout << "入栈和入队的顺序是" << ": ";
        push(Sqstack, 1);
        push(Sqstack, 5);
        push(Sqstack, 4);
        push(Sqstack, 3);
        push(Sqstack, 2);
        cout << "\n出栈的顺序是" << ": ";
        while(pull(Sqstack, x)){
            std::cout << x << " ";
        }
    }
    bool enQueue(SqQueue &s, int x){
        //队满则报错
        if((s.rear+1)%10 == s.front)    
            return false;
        //入队
        s.data[s.rear] = x;
        s.rear = (s.rear+1)%10;
        return true;
    }
    bool deQueue(SqQueue &s, int& x){
        //队空则报错
        if(s.front == s.rear)
            return false;
        //出队
        x = s.data[s.front];
        s.front = (s.front+1)%10;
        return true;
    }
    void testQueue(){
        int x = 0;
        //初始化队列
        sqQueue.front = 0;
        sqQueue.rear = 0;
        enQueue(sqQueue, 1);
        enQueue(sqQueue, 5);
        enQueue(sqQueue, 4);
        enQueue(sqQueue, 3);
        enQueue(sqQueue, 2);
        cout << "出队的顺序是" << ": ";
        while (deQueue(sqQueue, x)){
            std::cout << x << " ";
        }
    }
};

int main()
{
    Stack_Queue Stack_queue;
    Stack_queue.testStack();
    std::cout << std::endl;
    Stack_queue.testQueue();
    return 0;
}